#!/bin/sh
# Copyright (c) 2015-2025 Dirk Brenken (dev@brenken.org)
# This is free software, licensed under the GNU General Public License v3.

# (s)hellcheck exceptions
# shellcheck disable=all

export LC_ALL=C
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"

config="banip"
old_options="ban_loginput ban_logforwardwan ban_logforwardlan ban_blockinput ban_blockforwardwan ban_blockforwardlan"

for option in ${old_options}; do
	if uci -q get ${config}.global.${option} >/dev/null 2>&1; then
		old_values="$(uci -q get "${config}.global.${option}")"
		for value in ${old_values}; do
			case "${option}" in
				"ban_loginput" | "ban_logforwardwan")
					uci -q set "${config}".global.ban_loginbound="${value}"
				;;
				"ban_logforwardlan")
					uci -q set "${config}".global.ban_logoutbound="${value}"
				;;
			esac
		done
		uci -q delete "${config}.global.${option}"
	fi
done
[ -n "$(uci -q changes "${config}")" ] && uci -q commit "${config}"
exit 0
